package de.tabuma.soapforms.soapproject.controller;

import de.tabuma.soapforms.*;
import de.tabuma.soapforms.soapproject.entity.*;
import de.tabuma.soapforms.soapproject.logik.*;
import de.tabuma.lib.tabumacontroller;
import java.io.*;
import java.util.*;
import java.util.logging.*;
import javax.servlet.*;
import javax.servlet.http.*;
import com.google.appengine.api.users.*;

/**
 *
 * @author alefen
 */
public class create2 extends tabumacontroller {

    private static final Logger log = Logger.getLogger(create2.class.getName());

    public create2(String servlet, Hashtable parameter) {
        super(servlet, parameter);
    }

    @Override
    public void navigate(ServletContext context, HttpServletRequest request, HttpServletResponse response, PrintWriter out) {
        if(request.getParameter(constants.addSoapProject2)!=null) {

            UserService userService = UserServiceFactory.getUserService();
            User user = userService.getCurrentUser();

            String wsdlId = request.getParameter(constants.soapProjectWsdlId);
            int wsdlIdInt = Integer.valueOf(wsdlId).intValue();
            String url = request.getParameter(constants.soapProjectUrl);
            String method = request.getParameter(constants.soapProjectMethod);
            String customerId = request.getParameter(constants.customerId);
            String name = request.getParameter(constants.soapProjectName);
            int customerIdInt = Integer.valueOf(customerId).intValue();

            SoapProject soapProject = new SoapProject();
            soapProject.setMethod(method);
            soapProject.setCustomerId(customerIdInt);
            soapProject.setWsdlId(wsdlIdInt);
            soapProject.setWsdlUrl(url);
            soapProject.setName(name);

            int id = SoapProjectFacade.create(soapProject, user.getEmail());
            log.fine("created soap project with id:"+id);

            list list = new list(this.getServlet(), this.getParameter());
            list.navigate(context, request, response, out);

        }
    }
}
